import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import HomeView from '../views/test/HomeView.vue'

export type CusRouteRecordRaw = RouteRecordRaw & {
  cmpName?: string
}

const testChildren: CusRouteRecordRaw[] = [
  {
    cmpName: '主页',
    path: 'home',
    name: 'HomeView',
    component: HomeView,
  },
  {
    cmpName: '关于',
    path: 'AboutView',
    name: 'AboutView',
    component: () => import('../views/test/AboutView.vue'),
  },
  {
    cmpName: 'JSON编辑测试',
    path: 'JsonEditTest',
    name: 'JsonEditTest',
    component: () => import('../views/test/JsonEditTestView.vue'),
  },
  {
    cmpName: 'JSON编辑',
    path: 'JsonEditEl',
    name: 'JsonEditEl',
    component: () => import('../views/test/JsonEditElView.vue'),
  },
]

const routes: CusRouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/pda/JsonEdit',
  },
  {
    path: '/test',
    name: 'TestLayout',
    redirect: '/test/home',
    component: () => import('../views/test/layout/TestLayout.vue'),
    children: testChildren,
  },
  {
    path: '/pda',
    name: 'PdaLayout',
    component: () => import('../views/pda/layout/pdaLayout.vue'),
    children: [
      {
        path: 'JsonEdit',
        name: 'JsonEdit',
        component: () => import('../views/pda/JsonEditView.vue'),
      },
    ],
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes,
})

export default router

export { routes }
